#include<stdio.h>
#include<stdlib.h>
#include<iostream>
//#include"ARPListener.h"
#include<boost/thread/thread.hpp>
#include<signal.h>
#include"DNSListener.h"

using namespace std;

PacketListener* arp;
string* device;
string* dest;


void sig_term(int sig);
void usage();

int main(int argc, char** arg)
{
	if (argc < 2)
		usage();
	int opt;
	extern char* optarg;
	while ((opt = getopt(argc,arg,"s:d:")) != EOF)
	{
		switch(opt)
		{
			case 'd': dest = new string(optarg);break;
			case 's': device = new string(optarg); break;
			default: usage();
		};
	}
	arp = new DNSListener(dest,device);
	signal(SIGINT,&sig_term);
	while(true) {
		sleep(5);
	}
}

void sig_term(int sig)
{
	cout << "stopping...\n";
	arp -> stop();
	delete arp;
	delete device;
	delete dest;
	cout << "bye.\n";
	exit(0);
}

void usage()
{
	cout << "Usage: arpman -d destination_ip -s device" << endl;
	exit(1);
}
